package com.dp.appi.service.impl;

import com.dp.appi.dao.StageDao;
import com.dp.appi.service.StageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

/**
 * Created by bchen on 2016/5/17.
 */
@Service
@Transactional(rollbackFor=Exception.class)
public class StageServiceImpl implements StageService{

    private static final String PREFIX = "N";

    @Autowired
    private StageDao stageDao;

    /**
     * 创建新的踏勘点编号
     *
     * @param stage_id
     * @param pt_id
     * @return
     */
    @Override
    public String newExpNum(Long stage_id, Integer pt_id) {
        return stageDao.newExpNum(stage_id,pt_id);
    }

    @Override
    public Map<String, Object> getStageInfo(String stageId) {
        try{
            String sql="select * from p_stage where stage_id=?";
            return stageDao.findOneObject(sql,new Object[]{Long.parseLong(stageId)});
        }catch(NumberFormatException e){
            String sql="select * from p_stage where uuid=?";
            return stageDao.findOneObject(sql,new Object[]{stageId});
        }
    }

    /**
     * 获取项目归属
     *
     * @param projectId 项目id
     * @return
     */
    @Override
    public Map<String,Object> getProjectInfo(Long projectId) {
        String sql="select * from p_baseinfo where project_id=?";
        return stageDao.findOneObject(sql,new Object[]{projectId});
    }
   /* *//**
     * 获取最大编号值
     *
     * @param stage_id
     * @return
     *//*
    @Override
    public String getMaxNum(Long stage_id) {
        int maxNum = stageDao.getMaxNum(stage_id);
        stageDao.setMaxNum(maxNum+1,stage_id);
        return PREFIX+maxNum;
    }

    *//**
     * 设置最大阶段
     *
     * @param num
     * @param stage_id
     *//*
    @Override
    public void setMaxNum(int num, Long stage_id) {
        stageDao.setMaxNum(num+1,stage_id);
    }*/
}
